<template>
  <div class="more-list pages-box">
    <div class="header flex-center">
      <i class="iconfont icon-dajiantou" @click="$router.go(-1)"></i>精彩花絮
    </div>
    <div class="section">
      <div class="content">
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
          <van-list
            v-model="loading"
            :finished="finished"
            :finished-text="finishedText"
            @load="onLoad"
          >
            <div class="item-box" v-if="list.length > 0">
              <div
                class="item"
                v-for="(item, index) in list"
                :key="index"
                @click="goDetail(item)"
              >
                <div class="left">
                  <div class="title">
                    {{ item.title }}
                  </div>
                  <div class="time-box">
                    <div>发布单位：{{ item.brandName || "--" }}</div>
                    <div>发布时间：{{ item.createTime }}</div>
                  </div>
                </div>
                <div class="right" style="margin-left: 10px;">
                  <img v-lazy="ImgDomin(item.coverImg)" alt="" style="width: 160px;height: 100px;" />
<!--                  <div class="dianzan flex-between">-->
<!--                    <div class="flex-align">-->
<!--                      <i class="iconfont icon-yanjing"></i>-->
<!--                      {{ item.browseNum || 0 }}-->
<!--                    </div>-->
<!--                    <div class="flex-align">-->
<!--                      <i class="iconfont icon-dianzan"></i>-->
<!--                      {{ item.praiseNum || 0 }}-->
<!--                    </div>-->
<!--                  </div>-->
                </div>
              </div>
            </div>
            <div class="empty" v-else>
              <img
                style="width: 100%"
                src="../assets/img/common-empty.png"
                alt=""
              />
            </div>
          </van-list>
        </van-pull-refresh>
      </div>
    </div>
  </div>
</template>
<script>
import { getfsNewslist } from "@/api/activity";
export default {
  data() {
    return {
      params: {
        brandId: this.$route.query.id,
        pageNo: 1,
        pageSize: 10,
      },
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      finishedText: "没有更多了",
    };
  },
  methods: {
    onLoad() {
      getfsNewslist(this.params)
        .then((res) => {
          if (res.code == 0) {
            console.log(res,"111");
            let data = res.data;
            if (this.refreshing) {
              this.list = [];
              this.refreshing = false;
            }

            if (this.params.pageNo == 1) {
              this.list = data.records;
            } else {
              this.list = this.list.concat(data.records);
            }
            this.loading = false;

            if (this.list.length >= data.total) {
              this.finished = true;
            } else {
              this.params.pageNo++;
            }
            if (this.list.length == 0) this.finishedText = "暂无数据";
          } else {
            this.$toast(res.msg);
          }
        })
        .catch((err) => {
          this.$toast("数据获取失败，请稍后重试！");
        });
    },
    onRefresh() {
      this.params.pageNo = 1;
      // 清空列表数据
      this.finished = false;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    goDetail(item) {
      this.$router.push({
        name: "GagsDetail",
        query: {
          id: item.id,brandId:item.author
        }
      });
    },
  },
};
</script>
